#ifndef REGISTROUB_H
#define REGISTROUB_H

#include <sstream>
#include "zcurve.h"

template<size_t D, size_t K>
class RegistroUB : public Serializable {
    public:
        RegistroUB(){}

        RegistroUB(Point<D> p) {
            setPoint(p);
        }
        ZPoint<D*K> getKey() {
            return key;
        }
        Point<D> getPoint(){
            return point;
        }
        void setPoint(Point<D> point){
            this->point = point;
            key = zCurve.map(point);
        }
        void read(BinaryStream& in){
            key.read(in);
            point = zCurve.inv(key);
        }
        void write(BinaryStream& out){
            key.write(out);
        }
        std::string toString() {
            std::stringstream sout;
            sout << key.toString() << "[";
            for (uint8_t i = 0; i < D; i++){
                sout << point[i] << ";";
            }
            sout << "]";
            return sout.str();
        }
    private:
        ZCurve<D, K> zCurve;
        ZPoint<D*K> key;
        Point<D> point;
};

#endif // REGISTROUB_H
